package com.pcbly.web.components.taglib.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.util.TextProviderHelper;
import org.apache.struts2.views.jsp.ComponentTagSupport;

import com.opensymphony.xwork2.util.ValueStack;
import com.pcbly.web.components.taglib.Body;

public class BodyTag extends ComponentTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1993944108727323745L;
	private String items;
	private String loadingMask;
	@Override
	public Component getBean(ValueStack stack, HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		return new Body(stack);
	}
	public String getItems() {
		return items;
	}
	public void setItems(String items) {
		this.items = items;
	}
	public String getLoadingMask() {
		return loadingMask;
	}
	public void setLoadingMask(String loadingMask) {
		this.loadingMask = loadingMask;
	}
	protected void populateParams() {
		super.populateParams();
		items=getStringValue(items);
		loadingMask=getStringValue(loadingMask);
		
		Body body=(Body)component;
		body.setItems(items);
		body.setLoadingMask(loadingMask);
	}
	protected String getObjectValue(String obj) {
		if (obj != null && obj.startsWith("%{") && obj.endsWith("}")) {
			obj = obj.substring(2, obj.length() - 1);
			obj = String.valueOf(this.getStack().findValue(obj));
		} else {
			String tv = null;
			tv = obj;
			obj = String.valueOf(this.getStack().findValue(obj));
			if (obj == null || "".equals(obj)) {
				obj = TextProviderHelper.getText(tv, tv, this.getStack());
			}
		}
		return obj;
	}
	protected String getStringValue(String obj) {
		if (obj != null && obj.startsWith("%{") && obj.endsWith("}")) {
			obj = obj.substring(2, obj.length() - 1);
			obj = String.valueOf(this.getStack().findValue(obj));
		}
		return obj;
	}
	

}
